<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Components</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Components</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/components_rb.html">
                vendor/rails/actionpack/lib/action_controller/components.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="Components.html">Components</a> allow you to call other actions
for their rendered response while executing another action. You can either
delegate the entire response rendering or you can mix a partial response in
with your other content.
</p>
<pre>
  class WeblogController &lt; ActionController::Base
    # Performs a method and then lets hello_world output its render
    def delegate_action
      do_other_stuff_before_hello_world
      render_component :controller =&gt; &quot;greeter&quot;,  :action =&gt; &quot;hello_world&quot;, :params =&gt; { :person =&gt; &quot;david&quot; }
    end
  end

  class GreeterController &lt; ActionController::Base
    def hello_world
      render :text =&gt; &quot;#{params[:person]} says, Hello World!&quot;
    end
  end
</pre>
<p>
The same can be done in a view to do a partial rendering:
</p>
<pre>
  Let's see a greeting:
  &lt;%= render_component :controller =&gt; &quot;greeter&quot;, :action =&gt; &quot;hello_world&quot; %&gt;
</pre>
<p>
It is also possible to specify the controller as a class constant,
bypassing the inflector code to compute the controller class at runtime:
</p>
<p>
&lt;%= render_component :controller =&gt; GreeterController, :action =&gt;
&quot;hello_world&quot; %&gt;
</p>
<h2>When to use components</h2>
<p>
<a href="Components.html">Components</a> should be used with care.
They&#8216;re significantly slower than simply splitting reusable parts
into partials and conceptually more complicated. Don&#8216;t use components
as a way of separating concerns inside a single application. Instead,
reserve components to those rare cases where you truly have reusable view
and controller elements that can be employed across many applications at
once.
</p>
<p>
So to repeat: <a href="Components.html">Components</a> are a
special-purpose approach that can often be replaced with better use of
partials and filters.
</p>

    </div>


   </div>


  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Components/InstanceMethods.html">InstanceMethods</a></span>
        <span class="include-name">ActiveSupport::Deprecation</span>
      </div>
    </div>

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Components/ClassMethods.html" class="link">ActionController::Components::ClassMethods</a><br />
Module <a href="Components/HelperMethods.html" class="link">ActionController::Components::HelperMethods</a><br />
Module <a href="Components/InstanceMethods.html" class="link">ActionController::Components::InstanceMethods</a><br />

    </div>




      


    <!-- if method_list -->


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>